/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package net.tygzs.minerpg.Configuration.packet;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

/**
 *
 * @author Administrator
 */
public class Packet
{

    private String name;
    private List<ItemStack> items = new ArrayList<>();
    private boolean NewPlayerPacket;
    private final Map<String, Integer> times = new HashMap<>();

    /**
     * @return the name
     */
    public String getName()
    {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name)
    {
        this.name = name;
    }

    /**
     * @return the items
     */
    public List<ItemStack> getItems()
    {
        return items;
    }

    /**
     * @param items the items to set
     */
    public void setItems(List<ItemStack> items)
    {
        this.items = items;
    }

    /**
     * @return the NewPlayerPacket
     */
    public boolean isNewPlayerPacket()
    {
        return NewPlayerPacket;
    }

    /**
     * @param NewPlayerPacket the NewPlayerPacket to set
     */
    public void setNewPlayerPacket(boolean NewPlayerPacket)
    {
        this.NewPlayerPacket = NewPlayerPacket;
    }

    public void setTime(String name, int time)
    {
        this.times.put(name, time);
    }

    public int getTime(String name)
    {
        if (this.times.containsKey(name))
        {
            return this.times.get(name);
        }
        return 0;
    }

    public Map getTimes()
    {
        return this.times;
    }

    public int sendPacket(Player player)
    {
        int AirAmount = 0;
        for (ItemStack is : player.getInventory().getContents())
        {
            if (is == null)
            {
                AirAmount++;
                continue;
            }
            if (is.getType() == Material.AIR)
            {
                AirAmount++;
            }
        }
        if (AirAmount < this.items.size())
        {
            return this.items.size() - AirAmount;
        }
        for (ItemStack is : this.items)
        {
            player.getInventory().addItem(is);
        }
        int time = this.getTime(player.getName());
        time++;
        this.setTime(player.getName(), time);
        return 0;
    }
}
